home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-16 | 15.9 KB | 515 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: Command.cpp
- // Release Version: $ ODF 1 $
- //
- // Author: M.Boetcher
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "Embed.hpp"
-
- #ifndef COMMAND_H
- #include "Command.h"
- #endif
-
- #ifndef SELECT_H
- #include "Select.h"
- #endif
-
- #ifndef PROXY_H
- #include "Proxy.h"
- #endif
-
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- #ifndef FRAME_H
- #include "Frame.h"
- #endif
-
- #ifndef CONTENT_H
- #include "Content.h"
- #endif
-
- // ----- Framework Includes -----
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- // ----- OS Includes -----
-
- #ifndef FWORDCOL_H
- #include "FWOrdCol.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_Commands_defined
- #include <CmdDefs.xh>
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment opfEmbed
- #endif
-
- FW_DEFINE_AUTO(CEmbedEditCommand)
- FW_DEFINE_AUTO(CEmbedInsertCommand)
- FW_DEFINE_AUTO(CEmbedDropCommand)
- FW_DEFINE_AUTO(CEmbedDragCommand)
-
- //========================================================================================
- // CEmbedEditCommand
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CEmbedEditCommand constructor
- //----------------------------------------------------------------------------------------
-
- CEmbedEditCommand::CEmbedEditCommand(Environment *ev,
- ODCommandID commandID,
- CEmbedContent* content,
- FW_CFrame* frame,
- FW_CSelection* selection,
- FW_Boolean canUndo) :
- FW_CClipboardCommand(ev, commandID, frame, canUndo),
- fEmbedContent(content),
- fPastedProxy(NULL),
- fOldProxy(NULL)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedEditCommand destructor
- //----------------------------------------------------------------------------------------
-
- CEmbedEditCommand::~CEmbedEditCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedEditCommand::SaveUndoState
- //----------------------------------------------------------------------------------------
- void CEmbedEditCommand::SaveUndoState(Environment* ev) // Override
- {
- ODCommandID commandID = GetCommandID(ev);
-
- if (commandID == kODCommandCut || commandID == kODCommandClear)
- fPastedProxy = fEmbedContent->GetProxy();
- else if (commandID == kODCommandPaste)
- fOldProxy = fEmbedContent->GetProxy();
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedEditCommand::FreeUndoState
- //----------------------------------------------------------------------------------------
- void CEmbedEditCommand::FreeUndoState(Environment* ev) // Override
- {
- ODCommandID commandID = GetCommandID(ev);
-
- if (commandID == kODCommandCut || commandID == kODCommandClear)
- {
- delete fPastedProxy;
- }
- else if (commandID == kODCommandPaste)
- {
- // Delete the original proxy
- delete fOldProxy;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedEditCommand::SaveRedoState
- //----------------------------------------------------------------------------------------
- void CEmbedEditCommand::SaveRedoState(Environment *ev) // Override
- {
- if (GetCommandID(ev) == kODCommandPaste)
- fPastedProxy = fEmbedContent->GetProxy();
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedEditCommand::FreeRedoState
- //----------------------------------------------------------------------------------------
- void CEmbedEditCommand::FreeRedoState(Environment* ev) // Override
- {
- if (GetCommandID(ev) == kODCommandPaste)
- {
- // Delete the pasted proxy
- delete fPastedProxy;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedEditCommand::UndoIt
- //----------------------------------------------------------------------------------------
- void CEmbedEditCommand::UndoIt(Environment *ev) // Override
- {
- FW_CClipboardCommand::UndoIt(ev);
-
- switch (GetCommandID(ev))
- {
- case kODCommandCut:
- case kODCommandClear:
- this->RestorePart(ev);
- break;
-
- case kODCommandPaste:
- this->RemovePart(ev);
- this->RestoreOldPart(ev);
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedEditCommand::RedoIt
- //----------------------------------------------------------------------------------------
- void CEmbedEditCommand::RedoIt(Environment *ev) // Override
- {
- FW_CClipboardCommand::RedoIt(ev);
-
- switch (GetCommandID(ev))
- {
- case kODCommandCut:
- case kODCommandClear:
- this->RemovePart(ev);
- break;
-
- case kODCommandPaste:
- this->RemovePart(ev);
- this->RestorePart(ev);
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedEditCommand::RestorePart
- //----------------------------------------------------------------------------------------
- void CEmbedEditCommand::RestorePart(Environment *ev) // Override
- {
- fEmbedContent->SetProxy(fPastedProxy);
- fPastedProxy->AttachEmbeddedFrames(ev);
-
- GetPresentation(ev)->Invalidate(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedEditCommand::RemovePart
- //----------------------------------------------------------------------------------------
- void CEmbedEditCommand::RemovePart(Environment *ev) // Override
- {
- // Clear the selection, which includes detaching the proxy frames.
- fSelection->ClearSelection(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedEditCommand::RestoreOldPart
- //----------------------------------------------------------------------------------------
- void CEmbedEditCommand::RestoreOldPart(Environment* ev)
- {
- // restore the previous part, if any
- if (fOldProxy)
- {
- fEmbedContent->SetProxy(fOldProxy);
- if (fOldProxy)
- fOldProxy->AttachEmbeddedFrames(ev);
-
- // Force a redraw
- GetPresentation(ev)->Invalidate(ev);
- }
- }
-
- //========================================================================================
- // class CEmbedInsertCommand
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CEmbedInsertCommand constructor
- //----------------------------------------------------------------------------------------
-
- CEmbedInsertCommand::CEmbedInsertCommand(Environment* ev,
- FW_CEmbeddingFrame* frame,
- const FW_PFileSpecification& fileSpec,
- CEmbedContent* content)
- : FW_CInsertCommand(ev, frame, fileSpec, FW_kCanUndo),
- fPartContent(content),
- fEmbedSelection(NULL),
- fInsertedProxy(NULL),
- fOldProxy(NULL)
- {
- fEmbedSelection = (CEmbedSelection*) frame->GetPresentation(ev)->GetSelection(ev);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedInsertCommand destructor
- //----------------------------------------------------------------------------------------
-
- CEmbedInsertCommand::~CEmbedInsertCommand()
- {
- }
-
- //---------------------------------------------------------------------------------------
- // CEmbedInsertCommand::UndoIt
- //---------------------------------------------------------------------------------------
- void CEmbedInsertCommand::UndoIt(Environment* ev)
- {
- // remove the inserted part
- fEmbedSelection->ClearSelection(ev);
-
- // restore the previous part, if any
- fPartContent->SetProxy(fOldProxy);
- if (fOldProxy)
- fOldProxy->AttachEmbeddedFrames(ev);
-
- // Force a redraw
- GetPresentation(ev)->Invalidate(ev);
- }
-
- //---------------------------------------------------------------------------------------
- // CEmbedInsertCommand::RedoIt
- //---------------------------------------------------------------------------------------
- void CEmbedInsertCommand::RedoIt(Environment* ev)
- {
- // remove the original embedded part
- fEmbedSelection->ClearSelection(ev);
-
- // restore the inserted part
- fPartContent->SetProxy(fInsertedProxy);
- fInsertedProxy->AttachEmbeddedFrames(ev);
-
- // Force a redraw
- GetPresentation(ev)->Invalidate(ev);
- }
-
- //---------------------------------------------------------------------------------------
- // CEmbedInsertCommand::CommitDone
- //---------------------------------------------------------------------------------------
- void CEmbedInsertCommand::CommitDone(Environment* ev)
- {
- if (fOldProxy)
- {
- // Delete the original proxy
- delete fOldProxy;
- fOldProxy = NULL;
- }
- }
-
- //---------------------------------------------------------------------------------------
- // CEmbedInsertCommand::CommitUndone
- //---------------------------------------------------------------------------------------
- void CEmbedInsertCommand::CommitUndone(Environment* ev)
- {
- // Delete the inserted proxy
- delete fInsertedProxy;
- }
-
- //---------------------------------------------------------------------------------------
- // CEmbedInsertCommand::SaveUndoState
- //---------------------------------------------------------------------------------------
- void CEmbedInsertCommand::SaveUndoState(Environment* ev)
- {
- // Save the proxy for the part that's currently embedded
- fOldProxy = fPartContent->GetProxy();
- }
-
- //---------------------------------------------------------------------------------------
- // CEmbedInsertCommand::SaveRedoState
- //---------------------------------------------------------------------------------------
- void CEmbedInsertCommand::SaveRedoState(Environment* ev)
- {
- // Save the proxy for the part that was just inserted
- fInsertedProxy = fPartContent->GetProxy();
- }
-
- //========================================================================================
- // class CEmbedDropCommand
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CEmbedDropCommand constructor
- //----------------------------------------------------------------------------------------
-
- CEmbedDropCommand::CEmbedDropCommand(Environment* ev,
- CEmbedContent* content,
- FW_CFrame* frame,
- ODDragItemIterator* dropInfo,
- ODFacet* odFacet,
- const FW_CPoint& dropPoint) :
- FW_CDropCommand(ev, frame, dropInfo, odFacet, dropPoint, FW_kCanUndo),
- fEmbedContent(content),
- fDroppedProxy(NULL),
- fOldProxy(NULL)
- {
- fEmbedSelection = (CEmbedSelection*) frame->GetPresentation(ev)->GetSelection(ev);
- this->SetMenuStrings(ev, "Undo Drop", "Redo Drop");
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedDropCommand destructor
- //----------------------------------------------------------------------------------------
-
- CEmbedDropCommand::~CEmbedDropCommand()
- {
- }
-
- //---------------------------------------------------------------------------------------
- // CEmbedDropCommand::UndoIt
- //---------------------------------------------------------------------------------------
- void CEmbedDropCommand::UndoIt(Environment* ev)
- {
- FW_ASSERT(fDroppedProxy);
-
- // remove the dropped part
- fEmbedSelection->ClearSelection(ev);
-
- // restore the previous part, if any
- fEmbedContent->SetProxy(fOldProxy);
- if (fOldProxy)
- fOldProxy->AttachEmbeddedFrames(ev);
-
- // Force a redraw
- GetPresentation(ev)->Invalidate(ev);
- }
-
- //---------------------------------------------------------------------------------------
- // CEmbedDropCommand::RedoIt
- //---------------------------------------------------------------------------------------
- void CEmbedDropCommand::RedoIt(Environment* ev)
- {
- FW_ASSERT(fDroppedProxy);
-
- // remove the original embedded part
- fEmbedSelection->ClearSelection(ev);
-
- // restore the dropped part
- fEmbedContent->SetProxy(fDroppedProxy);
- fDroppedProxy->AttachEmbeddedFrames(ev);
-
- // Force a redraw
- GetPresentation(ev)->Invalidate(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedDropCommand::SaveUndoState
- //----------------------------------------------------------------------------------------
- void CEmbedDropCommand::SaveUndoState(Environment *ev)
- {
- // Save the proxy for the part that's currently embedded
- fOldProxy = fEmbedContent->GetProxy();
- }
-
- //---------------------------------------------------------------------------------------
- // CEmbedDropCommand::SaveRedoState
- //---------------------------------------------------------------------------------------
- void CEmbedDropCommand::SaveRedoState(Environment *ev)
- {
- // Save the proxy for the part that was just dropped
- fDroppedProxy = fEmbedContent->GetProxy();
- }
-
- //---------------------------------------------------------------------------------------
- // CEmbedDropCommand::CommitDone
- //---------------------------------------------------------------------------------------
- void CEmbedDropCommand::CommitDone(Environment* ev)
- {
- if (fOldProxy)
- {
- // Delete the original proxy
- delete fOldProxy;
- fOldProxy = NULL;
- }
- }
-
- //---------------------------------------------------------------------------------------
- // CEmbedDropCommand::CommitUndone
- //---------------------------------------------------------------------------------------
- void CEmbedDropCommand::CommitUndone(Environment* ev)
- {
- // Delete the dropped proxy
- delete fDroppedProxy;
- }
-
- //========================================================================================
- // class CEmbedDragCommand
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CEmbedDragCommand constructor
- //----------------------------------------------------------------------------------------
-
- CEmbedDragCommand::CEmbedDragCommand(Environment* ev,
- CEmbedContent* content,
- FW_CFrame* frame,
- CEmbedSelection* selection) :
- FW_CDragCommand(ev, frame, FW_kCanUndo),
- fEmbedContent(content),
- fEmbedSelection(selection),
- fSavedProxy(NULL),
- fDraggedProxy(NULL)
- {
- fDraggedProxy = content->GetProxy();
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedDragCommand destructor
- //----------------------------------------------------------------------------------------
-
- CEmbedDragCommand::~CEmbedDragCommand()
- {
- }
-
- //---------------------------------------------------------------------------------------
- // CEmbedDragCommand::UndoIt
- //---------------------------------------------------------------------------------------
- void CEmbedDragCommand::UndoIt(Environment* ev)
- {
- FW_ASSERT(fSavedProxy);
-
- // Restore saved proxy to the table
- fSavedProxy->AttachEmbeddedFrames(ev);
- fEmbedContent->SetProxy(fSavedProxy);
- }
-
- //---------------------------------------------------------------------------------------
- // CEmbedDragCommand::RedoIt
- //---------------------------------------------------------------------------------------
- void CEmbedDragCommand::RedoIt(Environment* ev)
- {
- fEmbedSelection->ClearSelection(ev);
- }
-
- //---------------------------------------------------------------------------------------
- // CEmbedDragCommand::SaveUndoState
- //---------------------------------------------------------------------------------------
- void CEmbedDragCommand::SaveUndoState(Environment* ev)
- {
- FW_UNUSED(ev);
-
- // Save the proxy for the part that was dragged
- fSavedProxy = fDraggedProxy;
- }
-
- //---------------------------------------------------------------------------------------
- // CEmbedDragCommand::FreeUndoState
- //---------------------------------------------------------------------------------------
- void CEmbedDragCommand::FreeUndoState(Environment* ev)
- {
- FW_UNUSED(ev);
-
- // fSavedProxy = NULL;
- FW_ASSERT(fSavedProxy);
- delete fSavedProxy;
- }
-
-
-